﻿
using System.Linq;
using System.Collections.Generic;
namespace MoneyManagerNET.Model
{
    public static class BankAccountExtensions
    {
        //------------------
        //---IBankAccount---
        //------------------
        public static IEnumerable<ITransaction> GetAllTransactions(this IBankAccount bankAccount) { return bankAccount.DepositList.Union(bankAccount.WirthdrawList); }
        public static decimal GetAccountBalance(this IBankAccount bankAccount) { return bankAccount.GetAllTransactions().Where(tran => tran.Status != (byte)TransactionStatus.Void).Sum(tran => tran.Amount * ((tran.FromAccount == bankAccount) ? -1 : 1)) + bankAccount.Balance; }
        public static decimal GetReconciledBalance(this IBankAccount bankAccount) { return bankAccount.GetAllTransactions().Where(tran => tran.Status == (byte)TransactionStatus.Reconciled).Sum(tran => tran.Amount * ((tran.FromAccount == bankAccount) ? -1 : 1)) + bankAccount.Balance; }
    }
}